<template>
  <div class="page-containers">
    <!--工具栏-->
    <div class="toolbar">
      <el-form :inline="true" :model="filters" :size="size" ref="filters">
        <el-row class="search-input">
          <el-row class="times">
            <el-form-item label="积分变动时间：">
              <el-date-picker v-model="filters.startTime" type="datetime" placeholder="开始时间" clearable
                @change="changeStartDate"
                :picker-options="startDateDisabled"></el-date-picker>
              <span class="times-to">-</span>
              <el-date-picker v-model="filters.endTime" type="datetime" placeholder="结束时间" class="input_postion"
                clearable
                @change="changeEndDate"
                :picker-options="endDateDisabled"></el-date-picker>
            </el-form-item>
          </el-row>
          <el-form-item label="变动方式：" label-width="112px" >
            <el-select v-model="filters.changeMode"  placeholder="全部" >
              <el-option label="参与平台活动  " value="9"></el-option>
              <el-option label="发布活动" value="10"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="变动类型：" label-width="112px" >
            <el-select v-model="filters.changeTypes"  placeholder="全部" >
              <el-option label="积分获取" value="1"></el-option>
              <el-option label="积分消耗" value="2"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="积分类型：" label-width="112px" >
            <el-select v-model="filters.integralType"  placeholder="全部" >
              <el-option label="消费积分" value="1"></el-option>
              <el-option label="任务积分" value="2"></el-option>
              <el-option label="活动积分" value="3"></el-option>
            </el-select>
          </el-form-item>
        </el-row>

        <el-row class="search-button-noborder">
            <el-form-item class="noMarginRight">
            <el-button   @click="resetForm('filters')" class="resetButton" icon="el-icon-refresh">重置</el-button>
          </el-form-item>
          <el-form-item class="noMarginRight">
            <kt-button icon="el-icon-search" :label="'搜索'" class="searchButton" @click="findPage(null)"/>
          </el-form-item>
        </el-row>
      </el-form>
    </div>
    <div class="toolbar">
      <table-column-filter-dialog
        ref="tableColumnFilterDialog"
        :columns="columns"
        @handleFilterColumns="handleFilterColumns"
      ></table-column-filter-dialog>
    </div>
    <!--表格内容栏-->
    <cy-table :loading="loading" :height="350" :data="pageResult" :columns="filterColumns" @findPage="findPage" @selectionChange="selectionChange"
              :showBatchDelete="false" showDetailOperation :showDeleteOperation="false" :showPushOperation="false"
              :showOperation="false"
              :showSelection="false"
              ref="CyTable">
    </cy-table>
  </div>
</template>

<script>
  import {exportExcel} from "@/utils/excel";
  import CyTable from "@/views/Core/JicTable";
  import KtButton from "@/views/Core/KtButton";
  import {format} from "@/utils/datetime";
  import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";
  import {validatePhone,validateContacts,isEmail,isNumber} from '@/utils/validate'
  import XLSX from "xlsx";
  export default {
     props:["memberUserId"],
    components: {
      CyTable,
      KtButton,
      TableColumnFilterDialog,
    },
    data() {
      return {
         loading: false, // 加载标识
        startTime:null,
        endTime:null,
        id:this.$route.params.id,
        thirdUserId:this.$route.params.id,
        businessId:"",
        deptMsg:localStorage.getItem('user'),//当前登录组织信息
        userId:localStorage.getItem("userId"),//当前登录用户id
        deptType:localStorage.getItem("deptType"),//当前登录用户所属组织类型
        createTime:null,
        changeMode:null,
        changeTypes:null,
        integralType:null,
        deptName:null,
        deptOption:[],
        content: null,
        size: "small",
        filters: {
          storeMember:1
        },
        columns:[
          {prop: "changeMode", label: "积分变动方式", minWidth: 130,formatter: this.changeModeFormatter},
          {prop: "changeTypes", label: "变动类型", minWidth: 120,formatter: this.changeTypesFormatter},
          {prop: "integral", label: "变动积分", minWidth: 120,formatter: this.integralFormatter},
          {prop: "integralType", label: "积分类型", minWidth: 120,formatter: this.integralTypeFormatter},
          {prop: "freezeIntegral", label: "积分余额", minWidth: 120},
          {prop: "changeTime", label: "积分变动时间", minWidth: 120},
        ],
        filterColumns: [],
        pageRequest: {pageNum: 1, pageSize: 10},
        pageResult: {},
        value:0,
        printPage:false,
        editLoading: false,
        reviewFormRules: {

        },
        checked: [],
        statusList: [],
         startDateDisabled: {}, //开始时间限制
      endDateDisabled: {} //结束时间限制
      };
    },
    methods: {
      changeStartDate: function() {
      var this_ = this;
      this_.endDateDisabled = {
        disabledDate: time => {
          if (this_.filters.startTime) {
            return (
              time.getTime() <= new Date(this_.filters.startTime).getTime()
            );
          }
        }
      };
    },
    changeEndDate: function() {
      var this_ = this;
      this_.startDateDisabled = {
        disabledDate: time => {
          if (this_.filters.endTime) {
            return time.getTime() >= new Date(this_.filters.endTime).getTime();
          }
        }
      };
    },
      // 获取分页数据
      findPage: function(data) {
        if(this.memberUserId==undefined){
            return;
        }
         this.loading = true;
        if(data != null && data.start != null){
          if(data.start != null){
            this.pageRequest.pageNum = data.start;
          }
          if(data.limit != null){
            this.pageRequest.pageSize = data.limit;
          }
        }
        let this_ = this;
        if (this_.filters == undefined || this_.filters == null) {
          this_.filters = {};
        }
        this_.filters.start = this.pageRequest.pageNum;
        this_.filters.limit = this.pageRequest.pageSize;
        this_.filters.memberUserId = this_.memberUserId;
        this.utils.request.findIntegralInfo(this_.filters, function (res) {
           this_.loading = false;
          if (res.data == null) {
            res.data = [];
            res.totle = 0;
          }else{
            this_.$refs.CyTable.findPage({content:res.data.rows,total:res.data.total});
          }
        });
      },


      // deptNameFormatter: function(){
      //   this.filters.deptName=JSON.parse(this.deptMsg).deptName;
      //   if(JSON.parse(this.deptMsg).deptType == 0){
      //     this.filters.deptName="母平台"
      //   }else if(JSON.parse(this.deptMsg).deptType == 1){
      //     this.filters.deptName="子平台"
      //   }else if(JSON.parse(this.deptMsg).deptType == 2){
      //     this.filters.deptName="商家"
      //   }else if(JSON.parse(this.deptMsg).deptType == 3){
      //     this.filters.deptName="店铺"
      //   }
      // },

      integralFormatter: function(row, column, cellValue, index){
       if(row.integralType==1){
          return "-"+cellValue;
       }else{
          return "+"+cellValue;
       }
      },

      integralTypeFormatter: function(row, column, cellValue, index){
        if(cellValue == 2){
          return '任务积分';
        }else if(cellValue == 1){
          return '消耗积分';
        }
        else if(cellValue==3){
          return '活动积分';
        }
      },


      changeTypesFormatter : function(row, column, cellValue, index){
        if(cellValue==1){
          return '积分获取'
        }else if(cellValue==2){
          return ' 积分消耗'}
      },

      changeModeFormatter: function(row, column, cellValue, index){
        if(cellValue==1){
          return '下单赠送'
        }else if(cellValue==2){
          return ' 注册赠送'
        }else if(cellValue==3){
          return ' 评价赠送'
        }else if(cellValue==4){
          return ' 充值赠送'
        }else if(cellValue==5){
          return ' 分享赠送'
        }else if(cellValue==6){
          return ' 点赞赠送'
        }else if(cellValue==7){
          return ' 晒单赠送'
        }else if(cellValue==8){
          return ' 收藏赠送'
        }else if(cellValue==8){
          return ' 收藏赠送'
        }else if(cellValue==8){
          return ' 收藏赠送'
        }else if(cellValue==9){
          return ' 参与平台活动'
        }else if(cellValue==10){
          return ' 发布活动'
        }else if(cellValue==11){
          return ' 兑换优惠券'
        }else if(cellValue==12){
          return ' 兑换红包'
        }else if(cellValue==13){
          return ' 兑换产品功能'
        }else if(cellValue==14){
          return ' 兑换付费内容'
        }else if(cellValue==15){
          return ' 退款返还'
        }else if(cellValue==16){
          return ' 取消评价返还'
        }else if(cellValue==17){
          return ' 取消点赞返还'
        }else if(cellValue==18){
          return ' 兑换抽奖活动'
        }
      },
      //获取子平台列表
      queryDeptOption(){
        let query={}
        let this_=this
        this_.utils.request.queryChildList(query,function(res){
          if(res.code == '0000'){
            this_.deptOption=res.data
          }
        })
      },
      //获取选择框数据
      selectionChange(val) {
        this.checked = val.selections;
      },

      // 时间格式化
      dateFormat: function (row, column, cellValue, index) {
        return format(row[column.property]);
      },

      resetForm(formName) { 
      this.filters={storeMember:1};
      this.findPage(null);
      },

      // 处理表格列过滤显示
      displayFilterColumnsDialog: function () {
        this.$refs.tableColumnFilterDialog.setDialogVisible(true);
      },
      // 处理表格列过滤显示
      handleFilterColumns: function (data) {
        this.filterColumns = data.filterColumns;
        this.$refs.tableColumnFilterDialog.setDialogVisible(false);
      },
      // 处理表格列过滤显示
      initColumns: function () {
        var temp = [];
        $.each(this.columns, function (key, val) {
          temp.push(val);
        });
        this.filterColumns = temp;
      }
    },
    mounted() {
      this.initColumns()
      // this.findPage()
      this.queryDeptOption();
    
      this.timer = setTimeout(()=>{   //设置延迟执行
          this.findPage();
      },200);

    }
  };
</script>

<style lang="scss" scoped>
.btns{
  width: 100%;
  /deep/ .el-form-item{
    margin-bottom: 20px !important;
    /deep/ .el-button{
      margin-left: 0 !important;
    }
  }
}
.mr20{
  margin-right: 20px !important;
}
.mr0{
  margin-right: 0 !important;
}
.noMarginRight{
  margin-right: 0 !important;
}
</style>
